package com.jr.controller;

import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.jr.util.SmsCode;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/smscode/")
public class SmsCodeController {


    @RequestMapping("createsmscode")
    public @ResponseBody String createCode(String phone, HttpSession session) throws Exception {
        SmsCode smsCode = new SmsCode();
        String code = smsCode.createCode();
        SendSmsResponse response = smsCode.sendSms(phone,code);
        System.out.println(response.getBody().getMessage());
        if("OK".toLowerCase().equals((response.getBody().getMessage()).toLowerCase())){
            return code;
        }
        return "false";
    }
}
